package com.fzu.commonutil.mapper;

import com.fzu.commonutil.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzu.commonutil.params.SelectResult;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zyq
 * @since 2023-03-26
 */
public interface UserMapper extends BaseMapper<User> {

    //查询所有
    public List<User> selectAll();

    //通过id查询
    public User selectId(int id);

    //通过账号查密码
    public String selectAccount(String account);

    //多条件查询（通过账号role角色查询）
    public List<User> selectByRole(Integer role);

    //增加一个账号
    public String addAccount(User user);

    //修改密码
    public String updatePassword(User user);

    //批量删除
    public void deleteByIds(int id);

    /**
     * 获取最近七天每天新增的用户数
     * @return
     */
    @Select("SELECT count(*) as total, date(create_time) as totalDate FROM `user` WHERE date_sub(curdate(), interval 6 day) <= date(create_time) group by date(create_time)")
    List<SelectResult> sevenDayNewUser();
}
